package main.java.learning.directory.Work.排序.Tmt;

/**
 * @author: tianmingtai
 * @create: 2021/02/23 10:11
 * @description: 插入排序
 */

public class InsertSortDay3 {

    public static void main(String[] args) {
        int[] arr = {49, 38, 65, 97, 23, 22, 76, 1};
        insertSort(arr, arr.length);
        for (int i : arr) {
            System.out.print(i + " ");
        }
    }


    public static void insertSort(int[] arr, int n) {
        for (int i = 1; i < n; i++) {
            for (int j = i; j > 0; j--) {
                if (arr[j] < arr[j - 1]) {
                    int temp = arr[j - 1];
                    arr[j - 1] = arr[j];
                    arr[j] = temp;
                }
            }
        }
    }
}
